﻿using Mimi.Models.DataModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mimi.ViewModels
{
    public class FilterViewModel : IFilterViewModel
    {
        #region Properties
        /// <summary>
        /// Filter model
        /// </summary>
        public FilterModel Model { get; set; }
        #endregion

        #region Method
        /// <summary>
        /// Default Constructor
        /// </summary>
        public FilterViewModel()
        {
            Model = new FilterModel();
        }

        /// <summary>
        /// Check the expense item using filter model
        /// </summary>
        /// <param name="expense"></param>
        /// <returns></returns>
        public bool Check(Expense expense)
        {
            if (!Model.IsFilteringOnBudget && !Model.IsFilteringOnDate)
            {
                return true;
            }

            bool result = false;

            if (Model.IsFilteringOnDate)
            {
                if (expense.Date >= Model.From && expense.Date <= Model.To)
                {
                    result = true;
                }
            }

            if (Model.IsFilteringOnBudget)
            {
                if (Model.BudgetIds.Contains(expense.SpentOn.PurposeId))
                {
                    result = true;
                }
                else
                {
                    result = false;
                }
            }

            return result;
        }
        #endregion
    }
}
